//
//  UIButton+WYButton.m
//  CirclePush
//
//  Created by admin on 2018/4/27.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "UIButton+WYButton.h"

@implementation UIButton (WYButton)
- (void)showBadgeOnItemIndex
{
    [self removeBadgeOnItemIndex:0];
    
    //新建小红点
    UIView *badgeView = [[UIView alloc]init];
    badgeView.tag = 888 + 0;
    badgeView.layer.cornerRadius = 2;//圆形
    badgeView.backgroundColor = [UIColor redColor];//颜色：红色
    CGRect tabFrame = self.frame;
    
    //确定小红点的位置
    float percentX = (0.6) ;
    CGFloat x = ceilf(percentX * tabFrame.size.width);
    CGFloat y = ceilf(0.4 * tabFrame.size.height);
    badgeView.frame = CGRectMake(x, y, 4, 4);//圆形大小为10
    [self addSubview:badgeView];
}
- (void)hideBadgeOnItemIndex
{
     [self removeBadgeOnItemIndex:0];
}

- (void)removeBadgeOnItemIndex:(int)index{
    //按照tag值进行移除
    for (UIView *subView in self.subviews) {
        if (subView.tag == 888+index) {
            [subView removeFromSuperview];
        }
    }
}


@end
